home *** CD-ROM | disk | FTP | other *** search
- /*-------------------------------------------------------------------------------------
- *
- * Simple Sample PowerTalk Application Framework
- *
- * ©1991-1993 Apple Computer
- *
- -------------------------------------------------------------------------------------*/
- /*
- * aevt.c -- appleevents code
- *
- * change history:
- *
- * SJF 08/23/93 1.0f1 update to final headers, fix comments
- * SJF 04/21/93 1.0b2 update to b2
- * SJF 03/01/93 1.0b1 added digital signatures
- * SJF 02/09/93 1.0b1 update to b1
- * SJF 10/13/92 1.0d4 update to a11
- * SJF 09/09/92 1.0d3 update to a9
- * SJF 05/07/92 1.0d2 update to a6
- * SJF 11/06/91 1.0d1 initial coding
- *
- */
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __GESTALTEQU__
- #include <GestaltEqu.h>
- #endif
-
- #ifndef __APPLEEVENTS__
- #include <AppleEvents.h>
- #endif
-
- #ifndef __OCESTANDARDMAIL__
- #include <OCEStandardMail.h>
- #endif
-
- #include "const.h"
- #include "myevents.h"
- #include "mytypes.h"
- #include "globals.h"
- #include "utils.h"
- #include "commands.h"
-
- #include "aevt.h"
-
- /* returns true if AppleEvents are available */
-
- Boolean SupportsAEVT(void)
- {
- OSErr err;
- long response;
-
- err = Gestalt(gestaltAppleEventsAttr,&response);
- if (err!=noErr)
- return false;
-
- return (response && (response << gestaltAppleEventsPresent));
- }
-
-
- /* called to process a high level event */
-
- void DoHighLevelEvent(EventRecord *ev)
- {
- AEProcessAppleEvent(ev);
- }
-
-
- /* register our AppleEvent handlers */
-
- void RegisterMyEvents(void)
- {
- OSErr err;
-
- if (!SupportsAEVT())
- return;
-
- err = AEInstallEventHandler(kCoreEventClass,kAEOpenApplication,(ProcPtr)&MyAEHandleOAPP,
- 0L,false);
- if (err!=noErr)
- return;
-
- err = AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,(ProcPtr)&MyAEHandleODOC,
- 0L,false);
- if (err!=noErr)
- return;
-
- err = AEInstallEventHandler(kCoreEventClass,kAEPrintDocuments,(ProcPtr)&MyAEHandlePDOC,
- 0L,false);
- if (err!=noErr)
- return;
-
- err = AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,(ProcPtr)&MyAEHandleQUIT,
- 0L,false);
- if (err!=noErr)
- return;
- }
-
-
- /* our OpenApplication handler - make a new window */
-
- pascal OSErr MyAEHandleOAPP(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon)
- {
- #pragma unused (reply,refCon)
- OSErr err;
-
- CommNew(); // since we were opened without a document, we should make an empty one
-
- err = MyGotRequiredParams(theAppleEvent);
- if (err!=noErr)
- return err;
- }
-
-
- /* our OpenDocument handler - open the documents */
-
- pascal OSErr MyAEHandleODOC(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon)
- {
- #pragma unused (reply,refCon)
- FSSpec myFSS;
- AEDescList docList;
- OSErr err;
- long index,itemsInList;
- Size actualSize;
- AEKeyword keywd;
- DescType returnedType;
- Size size;
- Boolean diskForm;
- LetterSpec myLetterSpec;
-
- err = AEGetParamDesc(theAppleEvent,keyDirectObject,typeAEList,&docList);
- if (err!=noErr)
- return err;
-
- err = MyGotRequiredParams(theAppleEvent);
- if (err!=noErr)
- return err;
-
- AECountItems(&docList,&itemsInList);
- for (index=1; index<=itemsInList; index++) {
- err = AESizeOfNthItem(&docList, index, &returnedType, &size);
- if (err!=noErr)
- return err;
-
- if (returnedType == typeLetterSpec) {
- diskForm = false;
- err = AEGetNthPtr(&docList,index,typeLetterSpec,&keywd,&returnedType,
- (Ptr)&myLetterSpec,sizeof(LetterSpec),&actualSize);
- } else if ((returnedType == typeAlias) || (returnedType == typeFSS)) {
- diskForm = true;
- err = AEGetNthPtr(&docList,index,typeFSS,&keywd,&returnedType,(Ptr)&myFSS,
- sizeof(myFSS),&actualSize);
- }
-
- if (err!=noErr)
- return err;
-
- if ((returnedType==typeLetterSpec) || (returnedType==typeAlias) ||
- (returnedType == typeFSS)) {
- err = HandleOpenDoc(diskForm, &myFSS, &myLetterSpec);
- if (err!=noErr)
- return err;
- }
- }
- err = AEDisposeDesc(&docList);
- return noErr;
- }
-
-
- /* our PrintDocument handler - print the documents */
-
- pascal OSErr MyAEHandlePDOC(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon)
- {
- #pragma unused (reply,refCon)
- FSSpec myFSS;
- AEDescList docList;
- OSErr err;
- long index,itemsInList;
- Size actualSize;
- AEKeyword keywd;
- DescType returnedType;
- Size size;
- Boolean diskForm;
- LetterSpec myLetterSpec;
-
- err = AEGetParamDesc(theAppleEvent,keyDirectObject,typeAEList,&docList);
- if (err!=noErr)
- return err;
-
- err = MyGotRequiredParams(theAppleEvent);
- if (err!=noErr)
- return err;
-
- err = AECountItems(&docList,&itemsInList);
- for (index=1; index<=itemsInList; index++) {
- err = AESizeOfNthItem(&docList, index, &returnedType, &size);
- if (err!=noErr)
- return err;
-
- if (returnedType == typeLetterSpec) {
- diskForm = false;
- err = AEGetNthPtr(&docList,index,typeLetterSpec,&keywd,&returnedType,
- (Ptr)&myLetterSpec,sizeof(LetterSpec),&actualSize);
- } else {
- diskForm = true;
- err = AEGetNthPtr(&docList,index,typeFSS,&keywd,&returnedType,(Ptr)&myFSS,
- sizeof(myFSS),&actualSize);
- }
-
- if (err!=noErr)
- return err;
-
- err = HandlePrintDoc(diskForm, &myFSS, &myLetterSpec);
- if (err!=noErr)
- return err;
- }
- err = AEDisposeDesc(&docList);
- return noErr;
- }
-
-
- /* our QuitApplication handler */
-
- pascal OSErr MyAEHandleQUIT(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon)
- {
- #pragma unused (reply,refCon)
- OSErr err;
-
- err = MyGotRequiredParams(theAppleEvent);
- if (err!=noErr)
- return err;
-
- gDone = true;
- }
-
-
- /* make sure we got all of the required parameters */
-
- OSErr MyGotRequiredParams(AppleEvent *theAppleEvent)
- {
- DescType returnedType;
- Size actualSize;
- OSErr err;
-
- err = AEGetAttributePtr(theAppleEvent,keyMissedKeywordAttr,typeWildCard,
- &returnedType,nil,0,&actualSize);
- if (err == errAEDescNotFound)
- err = noErr;
- else if (err==noErr)
- err = errAEEventNotHandled;
- return err;
- }
-